package de.koller.worlders.gameplay;

import de.koller.oceanFramework.OceanException;
import de.koller.oceanFramework.gl.util.IRenderableImage;
import de.koller.oceanFramework.tree.Mother;
import de.koller.worlders.WSea;
import de.koller.worlders.render.util.TextureRep;

abstract public class ProgressUnit extends WSea {

	@Mother private Progress progress;
	
	private final int id;
	private final int x, y;
	private IRenderableImage rimg;
	private boolean achieved = false;
	private boolean available = false;
	private boolean optional = false;

	public ProgressUnit( int id, int x, int y ) {
		this.id = id;
		this.x = x;
		this.y = y;
	}

	@Override
	protected void init() {
		super.init();
		
		for( ProgressUnit pu : progress.getUnits() )
			if( pu.id == this.id ) 
				throw new OceanException( "ID: " + id + " is already set" );
		
		progress.getUnits().add( this );
	}

	abstract public String[] achieveText();	
	abstract public String[] achieveReward();
	abstract public TextureRep getTextureRep();
	
	public void achieve() {
		if( achieved ) return;
		if( !available ) return;
		achieved = true;
		wroot.getGui().getAchGet().showAch();
	}

	public void setAvailable( boolean available ) {
		this.available = available;
	}

	public void setOptional( boolean optional ) {
		this.optional = optional;
	}

	public boolean isAchieved() {
		return achieved;
	}

	public boolean isAvailable() {
		return available;
	}

	public boolean isOptional() {
		return optional;
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public IRenderableImage getRimg() {
		return rimg;
	}

	public void setRimg( IRenderableImage rimg ) {
		this.rimg = rimg;
	}

	public int getId() {
		return id;
	}
	
}
